package main

import (
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	"net/http"
	"os"
	"practice/config"
)

const (
	STATIC = "./static"   // 静态文件所在路径
	TEMP   = "./template" // 模板所在路径
)

var Db *gorm.DB

// 初始化数据库
func init() {
	db, err := gorm.Open(config.MysqlDB["type"], config.ConnectionString)
	if err != nil {
		fmt.Println(err)
		os.Exit(0)
	}
	Db = db
	Db.SingularTable(config.SingularTable)
}

func main() {
	//
	http.HandleFunc("/index", Index)
	http.HandleFunc("/add", Add)
	http.HandleFunc("/edit", Edit)
	http.HandleFunc("/delete", Delete)
	http.ListenAndServe(":8080", nil)
	Db.Close()
}
